jQuery(document).ready(function($) {
    $("span.haveposition .persontest_tip_button").click(function(){
        $(this).nextAll('.hr_persontest_tipbox').show().focus();
        return false;
    });
    
    $("span.haveposition .hr_persontest_tipbox").blur(function(){
        $(this).hide();
    }).mouseover(function(){
        var t = $("#topmenu #searchpeople input").val();
        $(this).focus().unbind('blur');
    }).mouseout(function(){
        $(this).bind('blur',function(){$(this).hide();});
    });
    
    $("span.haveposition .hr_persontest_tipbox .replace_button").click(function(){
        $.metadata.setType("attr", "data");
        var metadata = $(this).metadata();
        var target = $(this);
        $.ajax({
            type: "POST",
            url: setpersontesturl,
            data: {id:metadata.persontestedid,jobid:metadata.jobid},
            dataType: 'json',
            beforeSubmit: function() {
               if (!showLoading("#jobneeds"))
                  return false;
            },
            success: function(data){
                if(data.error){
                    target.nextAll('span').html(data.error);
                }
                if(data.success){
                    target.nextAll('span').html('');
                    target.parents('.hr_persontest_tipbox:first').hide();
                    target.parents('.haveposition:first').removeClass('progress_notok').addClass('progress_ok').html("<i class='online_interview persontest'></i>&nbsp;性格评测&nbsp;<i class='finish ok'></i>");
                }
            }
         });        
    });
    
   $(".hr_position_infoshow a.showpositiondetail").on("click",function(){
      $.metadata.setType('attr', 'data');
      var data = $(this).metadata();
      $.ajax({
         type: "GET",
         url: OC.filePath('jobseeker', 'ajax', 'getjobdetails.php'),
         data: {jobid: data.jobid},
         dataType: 'html',
         success: function(result){
            var jobdetails = $('#jobseekerlookposition');
            $('.modal-body', jobdetails).html(result);
            jobdetails.modal();
         }
      });
   });
   
    $(".hr_position_infoshow a.showpositiondetail").on("click",function(){
       $("#jobseekerlookposition").modal();
    });

    $('#jos_managepersontest,#persontest_finished').on('click', '.lookresult_btn_a', function() {
        var sheetid = $(this).closest('a').data('id');
        $.ajax({
           type: "GET",
           url: OC.filePath('jobseeker', 'ajax', 'getjobseekertestresult.php'),
           data: {sheetid: sheetid},
           dataType: 'html',
           success: function(result){
        	   $("#resultpersontest_dialog").html(result).modal();
           }
        });
        return false;
     });
       
    $('#resultpersontest_dialog').on('show', function () {
       $(this).css('visibility', 'visible');
    });
    
    $('#resultpersontest_dialog').on('hidden', function () {
       $(this).css('visibility', 'hidden').show();
    });
    
    
});